/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.type;

import dex.compiler.model.base.Place;


/**
 *  An occurrence of a primitive, record or class type.
 */
public class BasicTypeNode extends TypeNode {
	
	
	/**
	 * The name of the type.
	 */
	private BasicTypeName name;
	
	
	/**
	 * True if the type was marked as local; false otherwise.
	 * Note that primitive type <i>are</i> local, but are not <i>marked</i>
	 * as local.
	 */
	private boolean local;
	

	/**
	 * Constructs a new basic type occurrence.
	 * 
	 * @param place  the place where the type occurred
	 * @param local  true if the type is marked as local, false otherwise
	 * @param name   the name of the basic type 
	 */
	public BasicTypeNode(Place place, boolean local, BasicTypeName name) {
		super(place);
		if (name == null) {
			throw new IllegalArgumentException();
		}
		this.local = local;
		this.name = name;
	}


	/**
	 * Returns the name of the basic type.
	 * 
	 * @return  the name of the type
	 */
	public BasicTypeName getName() {
		return name;
	}
	
	
	/**
	 * Returns true if the basic type was marked as local.
	 * In other words, returns true if the type name was preceded by a #.
	 * Note that primitive types are not marked as local even though they
	 * are always local types.
	 * 
	 * @return  the locality of the type being referenced
	 */
	public boolean isLocal() {
		return local;
	}
	
	
	@Override
	public void accept(TypeVisitor visitor) {
		visitor.visitBasicTypeNode(this);
	}


	@Override
	public String toString(){
		return name.toString();
	}

}
